import {
  AlipayCircleOutlined,
  LockOutlined,
  MobileOutlined,
  TaobaoCircleOutlined,
  UserOutlined,
  WeiboCircleOutlined,
} from '@ant-design/icons';
import { Alert, message, Tabs } from 'antd';
import React, { useState } from 'react';
import { ProFormCaptcha, ProFormCheckbox, ProFormText, LoginForm } from '@ant-design/pro-form';
import { history, useModel } from 'umi';
import Footer from '@/components/Footer';
import { login } from '@/services/user/account';
import { getFakeCaptcha } from '@/services/ant-design-pro/login';
import styles from './index.less';

const Login = () => {
  const handleSubmit = async (values) => {
    try {
      // 登录
      const msg = await login(values);

      if (msg.status === 'ok') {
        const defaultLoginSuccessMessage = '登录成功！';
        message.success(defaultLoginSuccessMessage);
        /** 此方法会跳转到 redirect 参数所在的位置 */
        if (!history) return;
        const { query } = history.location;
        const { redirect } = query;
        history.push(redirect || '/');
        return;
      }
    } catch (error) {
      const defaultLoginFailureMessage = '登录失败，请重试！';
      message.error(defaultLoginFailureMessage);
    }
  };

  return (
    <div className={styles.container}>
      <div className={styles.content}>
        <div>
          <LoginForm
            logo={<img alt="logo" src="/logo.png" />}
            title="系统登录"
            subTitle={'凯海智慧能源综合管理系统'}
            // initialValues={{
            //   autoLogin: true,
            // }}
            onFinish={async (values) => {
              await handleSubmit(values);
            }}
          >
            {/*{status === 'error' && loginType === 'account' && (*/}
            {/*  <LoginMessage content={'错误的用户名和密码(warren.davis)'} />*/}
            {/*)}*/}
            <ProFormText
              name="loginName"
              fieldProps={{
                size: 'large',
                prefix: <UserOutlined className={styles.prefixIcon} />,
              }}
              initialValue="zheng"
              placeholder={'用户名: zheng'}
              rules={[
                {
                  required: true,
                  message: '用户名是必填项！',
                },
              ]}
            />
            <ProFormText.Password
              name="password"
              fieldProps={{
                size: 'large',
                prefix: <LockOutlined className={styles.prefixIcon} />,
              }}
              initialValue="12345678"
              placeholder={'密码: 12345678'}
              rules={[
                {
                  required: true,
                  message: '密码是必填项！',
                },
              ]}
            />
            <div
              style={{
                marginBottom: 24,
              }}
            >
              <ProFormCheckbox noStyle>
                自动登录
              </ProFormCheckbox>
              <a
                style={{
                  float: 'right',
                }}
              >
                忘记密码 ?
              </a>
            </div>
          </LoginForm>
        </div>
      </div>
      <Footer />
    </div>
  );
};

export default Login;
